Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
What difference does it make of accessing through "Object" and through Object.constructor?

I have the following code:

    var obj2 = new Object();
    
    console.log(Object.isExtensible(obj2)); //returns 'true'
    console.log(obj2.constructor.isExtensible()); //returns 'false'

Could anyone explain why the first console print returns boolean 'true' and the second one 'false' and what difference it makes if isExtensible() is called either way.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The .constructor of an instance refers to the class / function that instantiates an instance. Since you're doing

var obj2 = new Object();

this means that obj2.constructor is the same as Object.

So

obj2.constructor.isExtensible()

is calling Object.isExtensible, but without an argument. isExtensible requires an argument. If you pass it the obj2, it'll do what you expect:

var obj2 = new Object();

console.log(Object.isExtensible(obj2)); //returns 'true'
console.log(obj2.constructor.isExtensible(obj2));
console.log(obj2.constructor === Object);

But that's still confusing. I'd recommend never using obj2.constructor - just use Object instead, it'll make more sense.

Usually, you'd probably only want to use the .constructor property when you don't already have a reference to the class - otherwise, it's easier to just reference the class.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda